home *** CD-ROM | disk | FTP | other *** search
- PROGRAM PI;
-
- {This program calculates the Monthly Principal and Interest payment
- for a loan. The user enters the Principal borrowed, Interest Rate,
- and the number of months in the payback period.}
-
- {Written by Gerald F. Seidl on 01/17/87
- Compuserve 72307,154
- Delphi GSEIDL}
-
- TYPE
- string79 = string[79];
- string2 = string[2];
-
- CONST
- black = 0;
- blue = 1;
- green = 2;
- cyan = 3;
- red = 4;
- magenta= 5;
- brown = 6;
- white = 15;
-
- VAR
- X,X1,Z,A,R : real;
- t : integer;
- running : boolean;
- DAY,MONTH,YEAR,
- HOUR,MINUTE : integer;
- AMORPM : string2;
-
- {****************************************************}
- Procedure Put_String (OUT_STRING : STRING79;
- LINE, COL, ATTRIB : INTEGER);
-
- Begin
- GOTOXY(COL,LINE);
- WRITE(OUT_STRING);
- End;
-
- {****************************************************}
- Procedure Put_Real (NUMBER : real;
- LINE,COL,ATTRIB,NUM_LENGTH,NUMDEC: integer);
-
- Var
- TEMP_STR: STRING79;
-
- Begin
- STR (NUMBER:NUM_LENGTH:NUMDEC,TEMP_STR);
- PUT_STRING(TEMP_STR,LINE,COL,ATTRIB);
- End;
-
- {****************************************************}
- Function YES : boolean;
-
- Var CH : CHAR;
-
- Begin
- read(CH);
- if ch in ['Y','y'] then yes:= true else yes:=false
- End;
-
- {****************************************************}
- Function MONOCHROME : boolean;
-
- TYPE reg_pack = record
- AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : INTEGER
- end;
-
- VAR regs : reg_pack;
-
- Begin
- intr(17,regs);
- if ((regs.ax) and $0030) = $30 then MONOCHROME := TRUE
- else MONOCHROME := false
- End;
-
- {****************************************************}
- Procedure Get_Date (var DAY,MONTH,YEAR : integer);
-
- TYPE reg_pack = record
- AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : INTEGER
- end;
- VAR
- regs : reg_pack;
-
- Begin
- With REGS Do
- Begin
- AX := $2A00;
- MSDos(REGS);
- Day :=Lo(DX);
- Month :=Hi(DX);
- Year :=CX;
- End;
- End;
-
- {***************************************************}
- Procedure Get_Time (var HOURS,MINUTES : integer);
-
- TYPE reg_pack = record
- AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : INTEGER
- end;
- VAR
- regs : reg_pack;
-
- Begin
- With REGS Do
- Begin
- AX:=$2C00;
- MSDos(REGS);
- HOURS:=Hi(CX);
- MINUTES:=Lo(CX);
- End;
- End;
-
- {************ MAIN PROGRAM SECTION ***************}
-
- Begin
- RUNNING:=true;
- AMORPM:='am';
- If not MONOCHROME then textmode(c80);
- If not MONOCHROME then textbackground(black);
- While RUNNING Do
- Begin
- ClrScr;
- Get_Date(DAY,MONTH,YEAR);
- Get_Time(HOUR,MINUTE);
- If not MONOCHROME then textcolor(cyan);
- GotoXY(1,2);
- write(MONTH,'/',DAY,'/',YEAR);
- GotoXY(19,2);
- Write('Calculate Monthly P & I payment for a loan');
- GotoXY(72,2);
- if HOUR > 12 then
- Begin
- HOUR:=HOUR-12;
- AMORPM:='pm';
- End;
- WriteLN(HOUR,':',MINUTE,AMORPM);
- GotoXY(0,3);
- WriteLN('------------------------------------------------------------------------------');
- Repeat
- GotoXY(19,5);
- If not MONOCHROME then TextColor(green);
- Write('Please enter to amount to borrow : ');
- If not MONOCHROME then TextColor(cyan);
- Read(A);
- Until A>=1;
- Repeat
- GotoXY(19,7);
- If not MONOCHROME then TextColor(green);
- Write(' Interest Rate : ');
- If not MONOCHROME then TextColor(cyan);
- Read(R);
- Until R>=1;
- Repeat
- GotoXY(19,9);
- If not MONOCHROME then TextColor(green);
- Write(' Term (in months) : ');
- If not MONOCHROME then TextColor(cyan);
- Read(T);
- Until t>=1;
- X:=((R/12)*0.01);
- X1:=1/((1-(1/(exp(T*ln(1+X)))))/(X*T*A));
- Z:=int(X1/T*100+0.99)*0.01;
- GotoXY(19,12);
- If not MONOCHROME then TextColor(green);
- Write('This would be your P & I payment :');
- If not MONOCHROME then TextColor(cyan);
- Put_Real(z,12,54,0,5,2);
- GotoXY(19,20);
- If not MONOCHROME then TextColor(green);
- Write('Do you want to enter another loan? (Y/N): ');
- If not MONOCHROME then TextColor(cyan);
- If YES then running:= TRUE else running:=FALSE;
-
- End;{while RUNNING}
-
- if not MONOCHROME then textmode;
- End. {main program}
-